package com.example.wordtext.service.impl;

import cn.hutool.core.convert.Convert;
import com.example.wordtext.service.DemoService;
import com.example.wordtext.utils.WordDocUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class DemoServiceImpl implements DemoService {


    @Override
    public void downloadDocx(HttpServletResponse response) {
        // 获取response对象
        Map<String, String> data = new HashMap<>();
        LocalDate now = LocalDate.now();
        data.put("年份", String.valueOf(now.getYear()));
        data.put("序号", "1");
        data.put("客户名称", "中铁集团");
        data.put("证件号", "56554885665565");
        data.put("year", String.valueOf(now.getYear()));
        data.put("month", String.valueOf(now.getMonthValue()));
        data.put("day", String.valueOf(now.getDayOfMonth()));
        data.put("设备融资贷款合同", "DKHT001");
        data.put("设备回购担保协议", "HGHT001");
        data.put("连续逾期", "1");
        data.put("连续逾期累计本息", "100");
        data.put("连续逾期选择", "☑");
        data.put("累计逾期", "");
        data.put("累计逾期累计本息", "");
        data.put("累计逾期选择", "□");
        data.put("number", "100");
        data.put("大写金额", Convert.digitToChinese(123.45));
        LocalDate localDate = now.plusDays(6);
        data.put("期限年", String.valueOf(localDate.getYear()));
        data.put("期限月", String.valueOf(localDate.getMonthValue()));
        data.put("期限日", String.valueOf(localDate.getDayOfMonth()));
        data.put("收款户名", "中铁集团有限公司");
        data.put("收款账号", "1212121212121212121212121212");
        data.put("收款账号开户行", "南京分行三叶草支行");
        WordDocUtil.fillTemplate(response, data);
    }


}